#!/usr/bin/env python
#coding=utf-8
import re
import urllib

def getHtml(url):
    try:
        page = urllib.urlopen(url)
        html = page.read()
        return html
    except Exception,e:
        print url +' open failed'
 
def getImg(html):
    reg = r'src="(.+?\.jpg)"'
    imgre = re.compile(reg)
    imglist = imgre.findall(html)
    for imgurl in imglist:
        print imgurl
        imgnum = imgurl.rfind('/')+1
        imgname = imgurl[imgnum:]
        try:
            urllib.urlretrieve(imgurl,'./1/%s' % imgname)
        except Exception,e:
        	print imgurl +' open failed'
        

html = getHtml("http://xxxxx.com")
getImg(html)